#ifndef SOS_LIST_H
#define SOS_LIST_H

#include <sel4/sel4.h>

#define SOS_LIST_TYPE    seL4_Word

#define SOS_LIST_SUCCESS (0)
#define SOS_LIST_OOM     (1)
#define SOS_LIST_NOENT   (2)

typedef struct list_node {
    SOS_LIST_TYPE value;
    struct list_node *next;
    struct list_node *prev;
} list_node;

typedef struct list {
    list_node *head;
    list_node *tail;
    int size;
} *list;

list list_init(void);
void list_destroy(list l);
int list_push_front(list l, SOS_LIST_TYPE val);
int list_push_back(list l, SOS_LIST_TYPE val);
SOS_LIST_TYPE list_pop_front(list l);
SOS_LIST_TYPE list_pop_back(list l);

int list_member(list l, SOS_LIST_TYPE val);
void list_map_left(list l, int (*fun)(SOS_LIST_TYPE*));
void list_map_right(list l, int (*fun)(SOS_LIST_TYPE*));
int list_remove_left(list l, SOS_LIST_TYPE val);
int list_remove_right(list l, SOS_LIST_TYPE val);

#endif // SOS_LIST_H
